package net.gz01.wallet.web.model;

import java.text.DecimalFormat;
import java.util.List;

import com.jfinal.plugin.activerecord.Page;

import net.gz01.wallet.common.ZOSearchCondition;
import net.gz01.wallet.common.ZOSqlHelper;
import net.gz01.wallet.web.model.base.BaseFeeModel;

/**
 * 费率模式
 * @author Reed
 * @date 2017年7月27日
 */
@SuppressWarnings("serial")
public class FeeModel extends BaseFeeModel<FeeModel> {
	public static final FeeModel dao = new FeeModel().dao();

	public Page<FeeModel> search(ZOSearchCondition sc) {
		int pageNumber = sc.page.getPageNum();
		int pageSize = sc.page.getNumPerPage();

		ZOSqlHelper sql = new ZOSqlHelper(" from bd_fee_model WHERE 1 = 1 ");
		sql.like("name", sc.get("name"));
		sql.equals("id", sc.get("id"));
		sql.orderBy("updateTime", "desc");
		return super.paginate(pageNumber, pageSize, "select *", sql.toString(), sql.getParams());
	}

	/**
	 * 根据md5查询费率模式
	 * @param md5
	 * @return
	 */
	public FeeModel selectByMd5(String md5) {
		return findFirst("select * from bd_fee_model where md5 = ?", md5);
	}

	/**
	 * 查询所有的费率模式
	 * @return
	 */
	public List<FeeModel> selectAll() {
		String sql = "SELECT * FROM bd_fee_model";
		return super.find(sql);
	}

	/**
	 * 查询需要加载到Reids的费率数据
	 * @return
	 */
	public List<FeeModel> selectToRedis() {
		String sql = "SELECT id, rate, floatingRate, minFee,maxFee FROM bd_fee_model";
		return super.find(sql);
	}

	public java.lang.String getMinFeeShow() {
		return new DecimalFormat("0.00").format(getMinFee()/100.0);
	}

	public java.lang.String getMaxFeeShow() {
		return new DecimalFormat("0.00").format(getMaxFee()/100.0);
	}
}
